<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.*,
						com.ophelisis.common.consts.ConstCode.MenuGNB,
						com.ophelisis.common.util.DateUtils,
						com.ophelisis.common.util.MenuUtil,
						com.ophelisis.common.util.StringUtil,
						com.ophelisis.common.consts.*,
						com.ophelisis.actions.system.*,
						com.ophelisis.persistence.domain.MenuAuthVO,
						com.ophelisis.persistence.domain.MenuVO"%>

<%
	String groupId = (String)request.getAttribute("_groupId");  /* gnb.jsp 에서 define 됨. */
	String menuTitle = (String)request.getAttribute("_menuNm");
	String userLevel = (String)session.getAttribute("userLevel");
	List<MenuAuthVO> menuAuthList = (List<MenuAuthVO>)session.getAttribute("menuAuthList");
	List<MenuVO> menuList = (List<MenuVO>)session.getAttribute("menuList");
	List<MenuGNB> constItems = MenuUtil.getMenus(groupId);

	if (groupId.equals("0")) {
		menuTitle = "메인화면";
	}
%>
<h1><%=menuTitle%></h1>
<ul class="leftul">
<%
	String mAction = "";
	String mDesc = "";
	String mDisplay = "";
	String mGrant = "";

	if (groupId.equals("0")) {
	} else {
		for (MenuGNB mgb : constItems) {
			if (Integer.parseInt(userLevel) >= Integer.parseInt(mgb.getAuth())) {
				mDesc = mgb.getDescription();
				mAction = "javascript:goMenu('" + mgb.getGroupId() + "','" + mgb.getMenuId() + "','','','" + mgb.getAction() + "','2')";
				mDisplay = "";
				mGrant = "";
				%>
				<li class="leftli <%=mDisplay%>" id="<%=mgb.getMenuId()%>"><a class="a" title="<%=mDesc%>" href="#" onclick="<%=mAction%>"><%=mgb.getName()%></a></li>
				<%
			}
		}
	
	    if (menuList != null) {
	    	for (int i = 0; i < menuList.size(); i++) {
	    		if (menuList.get(i).getMenuGroupId().equals(groupId)) {
		    		mDesc = menuList.get(i).getMenuDesc();
		    		mDisplay = menuList.get(i).getUseYn().equals("Y") ? "" : "nodisplay";
		    		
	    			if (Integer.parseInt(userLevel) >= 7) {
	    				mAction = "javascript:goMenu('" + menuList.get(i).getMenuGroupId() + "','" + menuList.get(i).getMenuId() + "','" + menuList.get(i).getMenuType() + "','" + menuList.get(i).getMenuGroupNm() + "','" + menuList.get(i).getMenuValue() + "','2')";
    		    		mGrant = "";
	    			} else {
	    				mDesc = "[ " + menuList.get(i).getMenuNm() + " ] 메뉴에 대한 접근 권한이 없습니다.";
    					mAction = "javascript:alert('" + StringUtil.escapeJavaScript(mDesc) + "')";
    					mGrant = "off";
    					
		    			for (int j = 0; j < menuAuthList.size(); j++) {
		    				if (menuList.get(i).getMenuId().equals(menuAuthList.get(j).getMenuId()) && !menuAuthList.get(j).getMenuAuth().equals("0")) {
		    		    		mAction = "javascript:goMenu('" + menuList.get(i).getMenuGroupId() + "','" + menuList.get(i).getMenuId() + "','" + menuList.get(i).getMenuType() + "','" + menuList.get(i).getMenuGroupNm() + "','" + menuList.get(i).getMenuValue() + "','" + menuAuthList.get(j).getMenuAuth() + "')";
		    		    		mGrant = "";
		    				}
		    			}
	    			}
		    		
		    		%>
		    		<li class="leftli <%=mDisplay%>" id="<%=menuList.get(i).getMenuId()%>"><a class="a <%=mGrant%>" title="<%=mDesc%>" href="#" onclick="<%=mAction%>"><%=menuList.get(i).getMenuNm()%></a></li>
		    		<%
	    		}
	    	}
	    }
	}
%>
</ul>
<form id="linkForm" name="linkForm" method="post">
	<input type="hidden" id="_groupId" name="_groupId" value="${_groupId}" />
	<input type="hidden" id="_menuId" name="_menuId" value="${_menuId}" />
	<input type="hidden" id="_menuType" name="_menuType" value="${_menuType}" />
	<input type="hidden" id="_menuNm" name="_menuNm" value="${_menuNm}" />
	<input type="hidden" id="_menuAuth" name="_menuAuth" value="${_menuAuth}" />
	<input type="hidden" id="_userLevel" name="_userLevel" value="${userLevel}" />
</form>
<script>
function goMenu(groupId, menuId, menuType, menuNm, action, authLevel) {
// 	alert(
// 			"groupId :: " + groupId
// 			+ "\n" + "menuId :: " + menuId
// 			+ "\n" + "menuType :: " + menuType
// 			+ "\n" + "menuNm :: " + menuNm
// 			+ "\n" + "action :: " + action
// 			+ "\n" + "authLevel :: " + authLevel
// 			);
	$("#_groupId").val(groupId);
	$("#_menuId").val(menuId);
	$("#_menuType").val(menuType);
	if (menuNm != "") {
		$("#_menuNm").val(menuNm);
	}
	$("#_menuAuth").val(authLevel);
	$("#linkForm").attr("action", action);
	$("#linkForm").submit();
}
</script>